<!--#include file="FastAsp/FastAsp.asp"-->
<%
'先输出HTML表单
If Not IsUploadRequest() Then
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文件上传示例</title>
    <style>
        body { font-family: Arial; margin: 40px; }
        .form-group { margin-bottom: 15px; }
        label { display: block; margin-bottom: 5px; }
        .btn { 
            background: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            cursor: pointer;
        }
        .preview {
            max-width: 200px;
            max-height: 200px;
            margin-top: 10px;
            display: none;
        }
        .message {
            padding: 10px;
            margin: 10px 0;
            border-radius: 4px;
        }
        .success { background: #dff0d8; color: #3c763d; }
        .error { background: #f2dede; color: #a94442; }
    </style>
</head>
<body>
    <h2>文件上传示例</h2>
    <form method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label for="title">标题:</label>
            <input type="text" name="title" id="title">
        </div>
        <div class="form-group">
            <label for="file">选择图片:</label>
            <input type="file" name="file" id="file" accept="image/*" onchange="previewImage(this)">
            <img id="preview" class="preview">
        </div>
        <div class="form-group">
            <input type="submit" value="上传" class="btn">
        </div>
    </form>

    <script>
    function previewImage(input) {
        var preview = document.getElementById('preview');
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
                preview.src = e.target.result;
                preview.style.display = 'block';
            }
            reader.readAsDataURL(input.files[0]);
        }
    }
    </script>
</body>
</html>
<%
'处理上传请求
Else
    Response.Write "<div style='font-family: Arial; margin: 40px;'>"
    
    '获取表单数据
    Dim title : title = Fast.Upload.GetForm("title")
    
    '获取上传文件
    Dim file : Set file = Fast.Upload.GetFile("file")
    
    '调试信息
    Response.Write "TotalBytes: " & Request.TotalBytes & "<br>"
    Response.Write "Error: " & Fast.Upload.Error_ & "<br>"
    
    If Not file Is Nothing Then
        Response.Write "File Info:<br>"
        Response.Write "FileName: " & file("FileName") & "<br>"
        Response.Write "ContentType: " & file("ContentType") & "<br>"
        Response.Write "FileSize: " & file("FileSize") & "<br>"
        
        '保存文件
        If Fast.Upload.SaveFile("file", "/uploads/") Then
            Response.Write "<div class='message success'>文件上传成功!</div>"
        Else
            Response.Write "<div class='message error'>上传失败: " & Server.HTMLEncode(Fast.Upload.Error_) & "</div>"
        End If
    Else
        Response.Write "<div class='message error'>请选择要上传的文件!</div>"
    End If
    
    Response.Write "<div><a href='up.asp'>返回上传页面</a></div>"
    Response.Write "</div>"
End If
%>